package entity

import (
	"time"

	"shqsoft.cn/pasnj/base"

	"github.com/jinzhu/gorm"
)

//XWPHDR 国际结算量导入
type XWPHDR struct {
	ID   int       `gorm:"AUTO_INCREMENT;primary_key;column:JLID"`
	JGDM string    `gorm:"column:JGDM;"`
	KHMC string    `gorm:"column:KHMC;"`
	JJBH string    `gorm:"column:JJBH;"`
	ACBL float64   `gorm:"column:ACBL"`
	QSR  time.Time `gorm:"column:QSR"`
	DQR  time.Time `gorm:"column:DQR"`
	DRJG string    `gorm:"column:DRJG;"`
	YWPZ string    `gorm:"column:YWPZ;"`
	DRRQ string    `gorm:"column:DRRQ;"`
}

//导入前执行分户处理
func xwphBeforeImport(tx *gorm.DB, params map[string]string) (err error) {
	prams := make([]interface{}, 1)
	prams[0] = params["DRRQ"]
	tx.Exec("DELETE FROM t_comp_loan_phjr WHERE LEFT(DRRQ,6)=LEFT(?,6) ", prams...)
	return nil
}

//xwphAfterImport 导入后执行
func xwphAfterImport(tx *gorm.DB, params map[string]string) (err error) {
	prams := make([]interface{}, 1)
	prams[0] = params["DRRQ"]
	err = tx.Exec("EXEC UP_COMP_LOAN_PHJR ?", prams...).Error
	if err != nil {
		return err
	}
	return nil
}

//TableName 国际中收导入表
func (XWPHDR) TableName() string {
	return "T_COMP_LOAN_PHJR"
}

//XWPHDREF 返回结构体
func XWPHDREF() base.EntityFunc {
	return func() interface{} {
		entity := XWPHDR{}
		return &entity
	}
}

//XWPHDRESF 返回结构体数组
func XWPHDRESF() base.EntitiesFunc {
	return func() interface{} {
		var entities []XWPHDR
		return &entities
	}
}

func init() {
	base.DaoPoolObj.Put("XWPHDR", base.NewDefaultDao(XWPHDREF(), XWPHDRESF(), nil))
	base.SetAfterCallBack("XWPHDR", xwphAfterImport)
	base.SetBeforeCallBack("XWPHDR", xwphBeforeImport)

}
